home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 004-kdeapps.lzm / usr / bin / workman2cddb.pl < prev   
Encoding:
Perl Script  |  2005-09-10  |  2.4 KB  |  87 lines

  1. #!/usr/bin/perl
  2. #
  3. # usage:  just start it.  Then copy the files to the local database.
  4. #
  5. # I have a extra cddb category (x-converted) for them, becauce I'm to
  6. # lazy to sort them all into the right category...
  7. #
  8. # make sure the output directory does *not* exist, the script refuses
  9. # to work if it does (just to make sure that it does not overwrite
  10. # something important)
  11. #
  12. # (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>  /  Copying: GNU GPL
  13. #
  14.  
  15. # config: output directory
  16. $dir="/tmp/cddb";
  17.  
  18. #############################################################################
  19.  
  20. $out=0;
  21. open(IN,"$ENV{'HOME'}/.workmandb") ||\
  22.         die "open $ENV{'HOME'}/.workmandb: $!";
  23. mkdir("$dir",0777) || die "mkdir $dir: $!";
  24.  
  25. while (<IN>) {
  26.     if (/^tracks/) {
  27.         if ($out) {
  28.             print OUT "EXTD=\n";
  29.             for ($i = 2, $n = 0; $i < $t[1]+2; $i++) {
  30.                 printf OUT "EXTT%d=\n",$i-2;
  31.             }
  32.             print OUT "PLAYORDER=\n";
  33.             close OUT;
  34.         }
  35.         @t = split;
  36.         for ($i = 2, $n = 0; $i < $t[1]+2; $i++) {
  37.             $len = $t[$i]/75;
  38.             for ($quer = 0; $len > 0; $quer += $len % 10, $len /= 10) {};
  39.             $n += $quer + ($len % 60);
  40.         }
  41.         $m = ($t[$t[1]+2] - int($t[2]/75));
  42.         $id = (($n % 0xff) << 24)  |  ($m << 8)  |  $t[1];
  43.         $magic = sprintf("%08x",$id);
  44.         open(OUT,">$dir/$magic") || die "open $dir/$magic: $!";
  45.         $out=1;
  46.     }
  47.  
  48.     $cdname = $1 if (/^cdname (.*)/);
  49.     if (/^artist (.*)/) {
  50.         $artist = $1;
  51.  
  52.         print OUT "# xmcd 2.0 CD database file\n";
  53.         print OUT "#\n";
  54.         print OUT "# Track frame offsets:\n";
  55.         for ($i = 2, $n = 0; $i < $t[1]+2; $i++) {
  56.             print OUT "#\t$t[$i]\n";
  57.         }
  58.         print OUT "#\n";
  59.         print OUT "# Disc length: $t[$t[1]+2] seconds\n";
  60.         print OUT "#\n";
  61.         print OUT "# Revision: 1\n";
  62.         print OUT "# Submitted via: wdb2cddb 1.0\n";
  63.         print OUT "#\n";
  64.         
  65.         print OUT "DISCID=$magic\n";
  66.         print OUT "DTITLE=$artist / $cdname\n";
  67.         print "$magic - $artist / $cdname\n";
  68.         $track=0;
  69.     }
  70.     if (/^track (.*)/) {
  71.         print OUT "TTITLE$track=$1\n";
  72.         $track++;
  73.     }
  74. }
  75.  
  76. close IN;
  77.  
  78. print OUT "EXTD=\n";
  79. for ($i = 2, $n = 0; $i < $t[1]+2; $i++) {
  80.     printf OUT "EXTT%d=\n",$i-2;
  81. }
  82. print OUT "PLAYORDER=\n";
  83. close OUT;
  84.  
  85. print "\n*** The CDDB files are in $dir ***\n\n";
  86.  
  87.